<?php

namespace App\Model;


class GameFreeTaskLog extends Model
{
    protected $table = 'game_free_task_log';
    protected $fillable = ['uid', 'game_id', 'task_id', 'fot_id', 'prize_num', 'complete_time', 'create_time', 'status', 'is_get'];

    public static function insertRecord($data)
    {
        try {
            self::query()->insert($data);
            return ['code' => 0, 'msg' => '插入成功！'];
        } catch (\Exception $e) {
            return ['code' => 1, 'msg' => $e->getMessage()];
        }
    }

    public static function getRecord($where)
    {
        try {
            $data = self::query()->where($where)->first();
            if (empty($data)) {
                return ['code' => 2, 'msg' => '未找到记录2！'];
            }
            return ['code' => 0, 'msg' => '获取成功！', 'data' => $data->toArray()];
        } catch (\Exception $e) {
            return ['code' => 1, 'msg' => $e->getMessage()];
        }
    }

    public static function getList($where)
    {
        try {
            $data = self::query()->where($where)->get();
            if (empty($data)) {
                return ['code' => 2, 'msg' => '未找到记录2！'];
            }
            return ['code' => 0, 'msg' => '获取成功！', 'data' => $data->toArray()];
        } catch (\Exception $e) {
            return ['code' => 1, 'msg' => $e->getMessage()];
        }
    }

    public static function count($where, $colum)
    {
        try {
            $data = self::query()->where($where)->count($colum . ' as num');
            if (empty($data)) {
                return ['code' => 2, 'msg' => '未找到记录2！'];
            }
            return ['code' => 0, 'msg' => '获取成功！', 'data' => $data->num];
        } catch (\Exception $e) {
            return ['code' => 1, 'msg' => $e->getMessage()];
        }
    }

}